package com.zeta.demo.seata.api;

import com.zeta.api.client.demo.IDemoSeata2Api;
import com.zeta.api.model.DemoDTO;
import com.zeta.demo.seata.service.IDemoSeata2Service;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zetaframework.base.result.ApiResult;
import org.zetaframework.controller.SuperBaseController;

/**
 * DemoSeata2服务 Feign接口实现
 *
 * @author gcc
 */
@Hidden // swagger文档忽略
@Slf4j
@RestController
@RequestMapping("/demo/seata2")
@RequiredArgsConstructor
public class DemoSeata2ApiImpl implements IDemoSeata2Api, SuperBaseController {

    private final IDemoSeata2Service service;

    /**
     * 尝试抛异常，测试seata事务回滚
     *
     * @param demoDTO demo表数据
     * @return 测试结果
     */
    @Override
    @PostMapping("/try")
    public ApiResult<Boolean> tryException(DemoDTO demoDTO) {
        return success(service.tryException(demoDTO));
    }
}
